var login= function(){

	this.initialize= function(){
		
		login();
	}
	
    this.login= function() {
		//openFB.init({appId: '338425986336267', tokenStore: window.localStorage});
		openFB.init({appId: '338425986336267'});
        openFB.login(
                function(response) {
					console.log("Status: "+response.status);
                    if(response.status === 'connected') {
                        alert('Facebook login succeeded, got access token: ' + response.authResponse.token);
                    } else {
                        alert('Facebook login failed: ' + response.error);
                    }
                }, {scope: 'email,read_stream,publish_stream'});
				
		this.getInfo();
    }

    this.getInfo= function() {
        openFB.api({
            path: '/me',
            success: function(data) {
                console.log(JSON.stringify(data));
				//window.localStorage.setItem("person",JSON.stringify(data))
                //document.getElementById("userName").innerHTML = data.name;
                //document.getElementById("userPic").src = 'http://graph.facebook.com/' + data.id + '/picture?type=small';
            },
            error: errorHandler});
		//localStorage["person"] = JSON.stringify(data);
		//window.localStorage.setItem("person",JSON.stringify(data));
    }

    function share() {
        openFB.api({
            method: 'POST',
            path: '/me/feed',
            params: {
                message: document.getElementById('Message').value || 'Testing Facebook APIs'
            },
            success: function() {
                alert('the item was posted on Facebook');
            },
            error: errorHandler});
    }

    this.revoke= function() {
        openFB.revokePermissions(
                function() {
                    alert('Permissions revoked');
                },
                errorHandler);
    }

    this.logout= function() {
        openFB.logout(
                function() {
                    alert('Logout successful');
                },
                errorHandler);
    }

    function errorHandler(error) {
        alert(error.message);
    }		
}